<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Gregwar\Captcha\CaptchaBuilder;
use Session;
use App\Model\Home\Login;
use DB;

class LoginController extends Controller
{
    /**
     * 渲染登陆页面
     *
     * @return \Illuminate\Http\Response
     */
    public function login()
    {
        //
        return view('home.login');
    }


    /**
     * 
     *
     * 获取验证码 调用MODEL的静态方法
     */
    public function code($id)
    {
        //
      // Login::getCode($id);
    }

  /**
     * 判断登陆信息
     * 调用MODEL
     * @return 
     */
    public function isLogin(Request $request)
    {
        //dd(session('user1'));
       return Login::getLogin($request);

    }
    /**
     * 判断注册信息
     * 调用MODEL
     * @return 
     */
    public function register()
    {
        
      return view('home.register');
    }
      /**
     * 判断注册信息
     * 调用MODEL
     * @return 
     */
    public function isreg(Request $request)
    {
     //处理图片上传
       if ($request->hasFile('photo')) {
              $file = $request->file("photo");
              if($file->isValid()){
              //获取上传文件名的后缀名
              $ext = $file->getClientOriginalExtension();
              //执行移动上传文件
              $photo_path = "images/user/";
              $filename = time().rand(1000,9999).".".$ext;
              $file->move($photo_path,$filename);
              $data['img']  = "/images/user/".$filename;
           }
        }


        //将表单数据塞入数组
        $data['username']   =  $request->username;
        $data['nickname']   =  $request->nickname;
        $data['sex']        =  $request->sex;
        $data['phone']      =  $request->phone;
        $data['password']   =  md5($request->password);
        $data['email']      =  $request->email;
        $data['time']       =  time();
        $data['status']     =  0;
        $data['add']        =  $request->add;
        //加入数据库
        DB::table('user')->insert($data);
        return redirect('home/login');

    }




}
